<?php
App::uses('AppController', 'Controller');

class RiportsorokController extends AppController {

	function isAuthorized(){
		if($this->Auth->user('csoport') == 1){		//admin jogosultságú júzerek
			return true;
		}
		return false;
	}

/**
 * admin_index method
 *
 * @return void
 */
	public function admin_index() {
		$this->Riportsor->recursive = 0;
		$this->set('riportsorok', $this->paginate());
	}

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_view($id = null) {
		$this->Riportsor->id = $id;
		if (!$this->Riportsor->exists()) {
			throw new NotFoundException(__('Invalid riportsor'));
		}
		$this->set('riportsor', $this->Riportsor->read(null, $id));
	}

/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add() {
		if ($this->request->is('post')) {
			$this->Riportsor->create();
			$this->request->data['Riportsor']['params'] = serialize($this->request->data['Riportsor']['params']);
			if ($this->Riportsor->save($this->request->data)) {
				$this->Session->setFlash(__('The riportsor has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The riportsor could not be saved. Please, try again.'));
			}
		}
		$riportok = $this->Riportsor->Riport->find('list');
		$this->set(compact('riportok'));
	}

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		$this->Riportsor->id = $id;
		if (!$this->Riportsor->exists()) {
			throw new NotFoundException(__('Invalid riportsor'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			$this->request->data['Riportsor']['params'] = serialize($this->request->data['Riportsor']['params']);
			if ($this->Riportsor->save($this->request->data)) {
				$this->Session->setFlash(__('The riportsor has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The riportsor could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Riportsor->read(null, $id);
		}
		$riportok = $this->Riportsor->Riport->find('list');
		$this->set(compact('riportok'));
	}

/**
 * admin_delete method
 *
 * @throws MethodNotAllowedException
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->Riportsor->id = $id;
		if (!$this->Riportsor->exists()) {
			throw new NotFoundException(__('Invalid riportsor'));
		}
		if ($this->Riportsor->delete()) {
			$this->Session->setFlash(__('Riportsor deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Riportsor was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
